local baohe = fk.CreateSkill {
  name = "baohe",
}

baohe:addEffect(fk.EventPhaseEnd, {
  mute = true,
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Play and #player:getCardIds("he") >1
  end,
  on_cost = function(self, event, target, player, data)
    local cards = player.room:askForDiscard(player, 2, 2, true, self.name, true, ".", "#baohe-discard::"..target.id, true)
    if #cards > 1 then
      event:setCostData(self,cards)
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(event:getCostData(self), self.name, player, player)
    local targets = {}
    for _, p in ipairs(player.room:getOtherPlayers(target)) do
      if p:inMyAttackRange(target) and p ~= player then
        table.insert(targets, p)
      end
    end
    room:useVirtualCard("slash", nil, player, targets, self.name, true)
  end,
})

local func={
  can_refresh = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.DamageCaused then
        return player:getMark("baohe_adddamage-phase") ~= 0 and data.card and table.contains(data.card.skillNames, "baohe")
      else
        if data.card.name == "jink" and data.toCard and data.toCard.trueName == "slash" and table.contains(data.toCard.skillNames, "baohe") then
          return data.responseToEvent.from == player.id
        end
      end
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DamageCaused then
      local num = player:getMark("baohe_adddamage-phase")
      data.damage = data.damage + num
    else
      room:addPlayerMark(player, "baohe_adddamage-phase", 1)
    end
  end,
}

baohe:addEffect(fk.DamageCaused,func )
baohe:addEffect(fk.CardUseFinished,func )

return baohe